<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-student-classes-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">班级名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">年级：</label>
				<div class="col-sm-8">
					<input id="grade" name="grade" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">班主任：</label>
				<div class="col-sm-8">
					<select id="masterTeacher" name="masterTeacherId" class="form-control">
					</select>
				</div>
			</div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
    <script type="text/javascript">
        $(function(){
        	var nameEle = $("#name");
    		var prefix = ctx + "module/student/classes";
    		
    		$("#form-student-classes-add").validate({
    			rules:{
                    name:{
                        required:true,
                        remote: {
                            url: prefix + "/checkClassName",
                            type: "POST",
                            dataType: "json",
                            data: {
                                className : function() {
                                    return $.trim(nameEle.val());
                                }
                            },
                            dataFilter: function(data, type) {
                                return data == "0";
                            }
                        }
                    },
                    masterTeacher:{
                        required:true
    				},
                    peopleNumber:{
                        required:true,
                        digits:true
                    }
    			},
                messages:{
                    "name": {
                      remote: "当前班级名称以存在!"
    				}
    			},
    			submitHandler: function(form) {
                    var serializeAfterValue = $(form).serialize() +
    				"&masterTeacherName=" + $("#masterTeacher option:selected").text();
                    $.operate.save(prefix + "/add", serializeAfterValue);
    			}
    		});
        	
        	$("#masterTeacher").select2({
				ajax: {
			        type:'GET',
			        url: prefix + "/queryMasterTeacherFormatSelect2",
			        delay: 250,
			        cache: true
			    }
			});
        })
	</script>
</body>
</html>
